<div class="content_filtro">
    <div class="filtro">
        <form id="form_filtro" method="post" action="">            
            <i>Pesquisar</i>
            <label><?php echo elemform::radio('stafiltro','stafiltro','1',$this->stafiltro); ?> Ativo</label>
            <label><?php echo elemform::radio('stafiltro','stafiltro','0',$this->stafiltro); ?> Inativo</label>
            
            <input type="submit" value="buscar" name="buscar" class="btn-pdr">
            
        </form>
    </div>
    <?php if($this->per_add){?>
    <div class="content-btn">
        <span>Nova Publicação</span><a href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit','id'=>'')); ?>">+</a>
    </div>
    <?php } ?>
</div>

<div class="content-list">
    
    <h2><?php echo $this->titulo;?></h2>
    
    <table id="tlist">
        <thead>
            <tr>
                <th>Data</th>
                <th>Usuário</th>
                <th style="width: 200px">Tópicos</th>
                <th style="width: 350px">&nbsp;</th>
                <th class="bc">&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($this->result as $row) { 
                
                $query = 'SELECT SQL_CACHE TPC_NOM FROM TOPICO WHERE TPC_id in('.$row['TPC_ID'].')';
                $result = $this->db->fetchAll($query);
                $topicos = '';
                foreach($result as $r){
                    $topicos .= $r['TPC_NOM'].', '; 
                }
                $topicos = substr($topicos, 0,-2);
                
                $cursos = '';
            if(strlen($row['ALU_ID']) > 0){
                $query = 'SELECT SQL_CACHE ALU_NOM FROM ALUNO WHERE ALU_ID in('.$row['ALU_ID'].') AND ALU_STA = 1 ORDER BY ALU_NOM';
                $result = $this->db->fetchAll($query);
                foreach($result as $r){
                    $cursos .= $r['ALU_NOM'].', '; 
                }
                $cursos = substr($cursos, 0,-2); 
            } else if(strlen($row['CUR_ID']) > 0){
                $query = 'SELECT SQL_CACHE n.NRT_NOM '
                        .' FROM CURSO c, CURSOBASE cb, NUMEROTURMA n '
                        .' WHERE c.CBS_ID = cb.CBS_ID AND c.CUR_TRM = n.NRT_ID AND c.CUR_ID in('.$row['CUR_ID'].') '
                        .' ORDER BY n.NRT_SEM ASC, n.NRT_NOM ASC, c.CUR_ID ASC';
                $result = $this->db->fetchAll($query);
                foreach($result as $r){
                    $cursos .= $r['NRT_NOM'].', '; 
                }
                $cursos = substr($cursos, 0,-2); 
            } else if(strlen($row['CBS_ID']) > 0){
                $query = 'SELECT SQL_CACHE CBS_NOM FROM CURSOBASE  WHERE CBS_ID in('.$row['CBS_ID'].') ORDER BY CBS_ORD ASC';
                $result = $this->db->fetchAll($query);
                foreach($result as $r){
                    $cursos .= $r['CBS_NOM'].', '; 
                }
                $cursos = substr($cursos, 0,-2); 
            }
            
            ?>
                <tr>
                    <td><?php echo Datetools::invertDH($row['PBC_DATHOR']); ?></td>
                    <td><?php echo $row['USU_NOME']; ?></td>
                    <td><?php echo $topicos; ?></td>
                    <td><?php echo $cursos; ?></td>
                    <td class="bc">
                        <?php if($this->per_edt){?><a class="btn-pdr" href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit', 'id' => $row['PBC_ID'])); ?>">Publicado</a><?php }?>
                        <?php if($this->per_del){?><a class="btn-pdr" href="javascript:void(0);" onclick="list_delete('<?php echo $this->controller; ?>', <?php echo $row['PBC_ID'] ?>, $(this));">Deletar</a><?php } ?>
                    </td> 
                </tr>
            <?php } ?>
        </tbody>
    </table>
</div>
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>